<?php

/**
 * 得到所有的报价信息
 * @return array
 */

function getPriceByPage($page,$pageSize=2){
	$PdoMySQL=new PdoMySQL;
	$tables = "bac_price";
    global $totalRows;
	$totalRows=count($PdoMySQL->find($tables,null,'*',null,null,null,null));
	global $totalPage;
	$totalPage=ceil($totalRows/$pageSize);
	if($page<1||$page==null||!is_numeric($page)){
		$page=1;
	}

	if($page>=$totalPage)$page=$totalPage;
	$offset=($page-1)*$pageSize;
	if($offset < 0){
		$offset = 0;
	}
	$rows=$PdoMySQL->find($tables,null,'*',null,null,null,array($offset,$pageSize));

	return $rows;

}

/**
 * 得到指定ID的报价信息
 * @return array
 */
function findPriceById($id){
	$PdoMySQL=new PdoMySQL;
	$tables = "bac_price";
	$row = $PdoMySQL->findById($tables, $id, 'id, custName, aTime');
	return $row;
}
/**
 * 编辑报价信息
 * @param int $id
 * @return string
 */
function editPrice($id){
	$arr=$_POST;
	$arr['aTime'] = date("Y-m-d H:i",time());

	$PdoMySQL=new PdoMySQL;
	$table = "bac_price";

	if($PdoMySQL->update($arr,$table, "id={$id}",'','')){
		$mes="编辑成功!<br/><a href='listPrice.php'>查看报价列表</a>";
	}else{
		$mes="编辑失败!<br/><a href='listPrice.php'>请重新修改</a>";
	}
	return $mes;
}

/**
 * 删除指定id报价
 * @param int $id
 * @return string
 */
function delPrice($id){
	$PdoMySQL=new PdoMySQL;
	$table = "bac_price";
	
	if($PdoMySQL->delete($table,"id={$id}")){
		$mes="删除成功!<br/><a href='listPrice.php'>查看报价列表</a>";
	}else{
		$mes="删除失败!<br/><a href='listPrice.php'>请重新删除</a>";
	}
	return $mes;
}
/**
 * 添加报价的操作
 * @return string
 */
function addPrice(){
	$PdoMySQL=new PdoMySQL;
	@$arr=$_POST;

	$arr['cTime'] = date("Y-m-d H:i",time());
	if($PdoMySQL->add($arr,"bac_price")){
		$mes="申请报价成功!<br/><a href='quotation.php'>继续添加</a>";
	}else{
		$mes="申请报价失败！<br/><a href='quotation.php'>重新添加</a>";
	}
	return $mes;
}